
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>

		<div class="panel panel">
			<div class="panel-body pan"  style=" overflow:auto; height:500px;" >
					<div class="form-body pal" >
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									 <label for="inputUsername">中文名称<span class='require' id="zhongwenName">*</span> </label>
										<div class="input-icon right">
											<input id="nameZh" type="text" class="form-control" value="" onchange="pinYin(this.value)"/>
									</div>
								</div>
							</div>

							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">英文名称<span class='require' id="yingwenName">*</span> </label>
									<div class="input-icon right">
										<input id="nameEn" type="text" class="form-control" onchange="proving(this.value);"/>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<div class="form-group">
									<label for="inputUsername">描述 </label>
									<div class="input-icon right">
										<textarea id="description" class="form-control"></textarea>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">排序<span class='require' id="paixu">*</span> </label>
									<div class="input-icon right">
										<input id="sort" type="text" class="form-control" />
									</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
								<label for="inputUsername">父节点<span class='require' id="paixu">*</span> </label>
									<div class="input-icon right">
									<div class="input-group input-group-sm mbs" >
										 <input id="parentclassname" type="text" placeholder="根目录"  class="form-control" disabled="true"  />
										 <span class="input-group-btn"><button  onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>		
										 <input id="parentClassid" type="hidden" value="00" class="form-control" />
									</div>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							 <div class="col-xs-6">
								 <div class="form-group">
									<label for="inputUsername">是否加工平台展示<span class='require'>*</span> </label>
		                         	 <div class="input-icon right">
		                               <select  id="display"  class="form-control">
		                                   <option value="1">是</option>
		                                   <option value="0">否</option>
		                               </select>    
		                         	</div>
		                        </div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">图标</label>
									<div class="input-icon right">
										<input id="icon" type="text" class="form-control" />
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">是否前台首页快捷入口<span class='require'>*</span> </label>
									 <div class="input-icon right">
		                               <select  id="indexEntrance"  class="form-control">
		                               	   <option value="0">否</option>
		                                   <option value="1">是</option>
		                               </select>    
		                         	</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">是否在最新更新模块展示<span class='require' >*</span> </label>
									 <div class="input-icon right">
		                               <select  id="indexLatestUpdate"  class="form-control">
		                               	   <option value="0">否</option>
		                                   <option value="1">是</option>
		                               </select>    
		                         	</div>
								</div>
							</div>
						</div>	
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">是否普通检索知识库<span class='require'>*</span> </label>
									 <div class="input-icon right">
		                               <select  id="generalSearch"  class="form-control">
		                               	   <option value="0">否</option>
		                                   <option value="1">是</option>
		                               </select>    
		                         	</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">是否高级检索知识库<span class='require'>*</span> </label>
									 <div class="input-icon right">
		                               <select  id="advancedSearch"  class="form-control">
		                               	   <option value="0">否</option>
		                                   <option value="1">是</option>
		                               </select>    
		                         	</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
								<label for="inputUsername">推荐知识库<!-- <span class='require' id="paixu">*</span> --> </label>
									<div class="input-icon right">
									<div class="input-group input-group-sm mbs" >
										 <input id="recommendClassName" type="text" placeholder="请选择知识库" class="form-control" disabled="true"  />
										 <span class="input-group-btn"><button  onclick="recommendClass()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择推荐..</button></span>		
										 <input id="recommendClassEn" type="hidden" value="" class="form-control" />
									</div>
									</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">是否首页导航入口<span class='require'>*</span> </label>
									 <div class="input-icon right">
		                               <select  id="indeNavigation"  class="form-control">
		                               	   <option value="0">否</option>
		                                   <option value="1">是</option>
		                               </select>    
		                         	</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label for="inputUsername">导航页推荐类型<span class='require'>*</span> </label>
									 <div class="input-icon right">
		                               <select  id="navigationDataType"  class="form-control">
		                               	   <option value="0">按更新时间</option>
		                                   <option value="1">按推荐数据</option>
		                               </select>    
		                         	</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
								<label for="inputUsername">检索结果页显示按钮</label>
									<div class="input-icon right">
									<div class="input-group input-group-sm mbs" >
										 <input id="webListButtonsName" type="text" placeholder="请选择..."  class="form-control" disabled="true"  />
										 <span class="input-group-btn">
										 	<button  onclick="showClassButton()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择按钮..</button>
										 	<button  onclick="deleteClassButton()" type="button" data-toggle="dropdown" class="btn btn-sm btn-primary">清空</button>
										 </span>		
										 <input id="webListButtons" type="hidden" value="" class="form-control" />
									</div>
									</div>
								</div>
							</div>
							</div>
							<div class="row">
								<div class="col-xs-6">
									 <div class="form-group">
										<label for="inputUsername">是否开启数字资源交易系统<span class='require'>*</span> </label>
			                         	 <div class="input-icon right">
			                               <select  id="pay"  class="form-control">
			                                   <option value="0">关闭</option>
			                                   <option value="1">启用</option>
			                               </select>    
			                         	</div>
			                        </div>
								</div>
								<div class="col-xs-6">
									<div class="form-group">
										<label for="inputUsername">资源详情页URL地址</label>
										<div class="input-icon right">
											<input id="detailUrl" type="text" class="form-control" />
										</div>
									</div>
								</div>
								
							<div class="col-xs-6">
								<div class="form-group">
								<label for="inputUsername">资源库标识 </label>
									<div class="input-icon right">
									<div class="input-group input-group-sm mbs" >
										 <input id="knowledgeDbShow" type="text" placeholder="请选择标识" class="form-control" disabled="true"  />
										 <span class="input-group-btn"><button  onclick="recommendDb()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择推荐..</button></span>		
										 <input id="knowledgeDb" type="hidden" value="" class="form-control" />
									</div>
									</div>
								</div>
							</div>
						</div>	
	            <input id="mainid" type="hidden"  class="form-control" /> 
				<input id="winid" type="hidden"  class="form-control" /> 
			</div>
		</div>
	</div>
<?}?>
<script>
var classid = window.parent.getclassid();
var  classname=window.parent.getclassname();
var kk = window.parent.getkk();
var sum = window.parent.getsum();

	$(function(){  
	 $("#sort").val(sum);
	 $("#parentclassname").val(classname);
		if(kk==1){
			demo1();
		}
	});
	 	
function savedomainZTree() {
		parent.layer.open({
			type : 2,
			area :[ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			title:"选择所属分类",
			shadeClose : true,
			//move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content :["knowledge-Domain-domain-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {			
			  var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};


	function saveclassZTree() {
		parent.layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择父节点",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["knowledge-Classes-class-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	function Page() {
		if ($.trim($("#sort").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}
		if (isNaN($("#sort").val())) {
			alert("必须是数字");
			return null;
		}
		/* if($.trim($("#description").val()).length<1) {
    	        	alert('描述不能为空！');
    	        	return null;
    	        } */
   	     if($.trim($("#nameZh").val()).length<1) {
   	        	alert('中文名不能为空！');
   	        	return null;
   	        }   
		$.ajax({
					type : "post",
					url : "./KnowledgeClassesclasssave.do",
					data : {
						"id" : kk,
						"nameEn" : $("#nameEn").val(),
						"nameZh" : $("#nameZh").val(),
						"description" : $("#description").val(),
						"sort" : $("#sort").val(),
						"classid" : classid,
						"domainid" : $("#mainid").val(),
						"parentClassid" : $("#parentClassid").val(),
						"display":$("#display").val(),
						"icon":$("#icon").val(),
						"indexEntrance":$("#indexEntrance").val(),
						"indexLatestUpdate":$("#indexLatestUpdate").val(),
						"generalSearch":$("#generalSearch").val(),
						"advancedSearch":$("#advancedSearch").val(),
						"recommendClassEn":$("#recommendClassEn").val(),
						"navigationDataType":$("#navigationDataType").val(),
						"indeNavigation":$("#indeNavigation").val(),
						"webListButtons":$("#webListButtons").val(),
						"pay":$("#pay").val(),
						"detailUrl":$("#detailUrl").val(),
						"knowledgeDb":$("#knowledgeDb").val(),
					},
					dataType : "json",
					async : false,
					success : function(data) {
						var index = parent.layer.getFrameIndex(window.name);
						window.parent.get();
						parent.layer.msg('添加或编辑成功');
						parent.layer.close(index);
					},
					error : function(data) {
						alert("请求失败");
					}
				});
	}
	function demo1() {
		$.ajax({
					type : "post",
					url : "./KnowledgeClassesclassedit.do",
					data : {
						"id" : classid
					},
					dataType : "json",
					success : function(res) {
						for(var i=0;i<res.length;i++){
							if(res[i].classes.display==0){
								selected("display","0");
							}else{
								selected("display","1");
							}
							$("#nameZh").val(res[i].classes.nameZh);
							$("#nameEn").val(res[i].classes.nameEn);
						 	document.getElementById('nameEn').disabled = true;
							$("#sort").val(res[i].classes.sort);
							$("#icon").val(res[i].classes.icon);
							$("#detailUrl").val(res[i].classes.detailUrl);
							$("#knowledgeDb").val(res[i].classes.db);
							$("#knowledgeDbShow").val(res[i].dbName);
							selected("indexEntrance",res[i].classes.indexEntrance);
							selected("indexLatestUpdate",res[i].classes.indexLatestUpdate);
							selected("generalSearch",res[i].classes.generalSearch);
							selected("advancedSearch",res[i].classes.advancedSearch);
							selected("navigationDataType",res[i].classes.navigationDataType);
							selected("indeNavigation",res[i].classes.indeNavigation);
							selected("pay",res[i].classes.pay);
							$("#description").val(res[i].classes.description);
							//$("#classid").val(res[0].parentClass._id);
							if (res[i].pid != null) {
								$("#parentclassname").val(res[i].pid.nameZh);
								$("#parentClassid").val(res[i].pid.id);
							} else {
								$("#parentclassname").val("根节点");
								$("#parentClassid").val("0");
							}
							$("#recommendClassName").val(res[i].recommendClassZh);
							$("#recommendClassEn").val(res[i].classes.recommendClassEn);
							$("#webListButtons").val(res[i].classes.webListButtons);
							$("#webListButtonsName").val(res[i].ClassesbuttonName);
							var domainname = "";
							var domainid="";
							if (res[i].classes.domain != null) {
								for ( var j = 0; j < res[i].classes.domain.length-1; j++) {
									domainname += res[i].classes.domain[j].nameZh+",";
									domainid+=res[i].classes.domain[j].id+",";
								}
								domainname+=res[i].classes.domain[res[i].classes.domain.length-1].nameZh;
								domainid+=res[i].classes.domain[res[i].classes.domain.length-1].id;
							}
							$("#mainid").val(domainid);
							$("#domainname").val(domainname);
						}
					},
					error : function(res) {
						alert("请求失败");
					}
				});
	}
	function proving(aa) {
	if ($.trim(aa).length < 1) {
			alert('英文名不能为空！');
			return null;
		}
	if ($.trim(aa).length > 32) {
		alert('英文名长度过长！');
		$("#nameEn").val("");
		return null;
	}
		//alert(aa);
		$.ajax({
			type : "post",
			url : "./KnowledgeclassProving.do",
			data : {
				"name" : aa
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data.result!=1)
				{
				alert("表名不可用，重命名或者不符合规则");
				$("#nameEn").val("");
				}
				
			},
			error : function(data) {
				alert("请求失败");
			}
		});

	}
	function selected(selectname,selectid){
	 $("#"+selectname+" option").each(function(){ //遍历全部option
		      var v = $(this).val(); //获取option的内容
		      if(v == selectid){
		        $(this).attr("selected","selected");
		      }
		}); 
	}

//汉字转拼音
  function pinYin(pinyinName){
  	if(kk != 1){
		$.ajax({
			type : "post",
			url : "hanziToinitial.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].length > 32){
					layer.msg('自动转换英文名长度过长!请手动输入！');
					$("#nameEn").val("");
				}else{
					$("#nameEn").val(data);
				}
				
			},
			error : function(data) {
				alert("请求失败");
			}
		})
	 }
	}
	var recommendClassEns;
	function getrecommendClassEns() {
		return recommendClassEns;
	}
	//推荐类
	function recommendClass() {
		recommendClassEns = $("#recommendClassEn").val();
		parent.layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"推荐知识库",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["knowledge-Classes-recommendClass-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	var knowledgeDb;
	function getknowledgeDb() {
		return knowledgeDb;
	}
	//资源库标识
	function recommendDb() {
		knowledgeDb = $("#knowledgeDb").val();
		parent.layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"资源库标识",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["knowledge-Classes-db-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	//检索结果页显示按钮
	function showClassButton() {
		parent.layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择按钮",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["knowledge-Classes-class-button.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	function deleteClassButton(){
		$("#webListButtons").val("");
		$("#webListButtonsName").val("");
	}
</script>